package com.kly.cashmall.module.index.presenter;

import com.kly.cashmall.bean.BaseEntity;
import com.kly.cashmall.bean.IndexBean;
import com.kly.cashmall.framework.mvp.BaseViewPresenter;
import com.kly.cashmall.services.Network;
import com.kly.cashmall.services.Params;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * @author
 */
public class IndexPresenter extends BaseViewPresenter<IndexViewer> {
    public IndexPresenter(IndexViewer viewer) {
        super(viewer);
    }

    @Override
    public void willDestroy() {

    }

    public void getProductHome() {
        rxManager.add(Network.getApi().getProductHome().subscribeOn(Schedulers.io()).observeOn
                (AndroidSchedulers.mainThread()).subscribe(new Consumer<IndexBean>() {
            @Override
            public void accept(IndexBean bean) throws Exception {
                if (getViewer() != null) {
                    getViewer().onGetProductHomeSuccess(bean);
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
            }
        }));

    }

    public void getHomeProductClick(String categoryCode) {
        Params params = new Params();
        params.put("categoryCode",categoryCode);
        rxManager.add(Network.getApi().getHomeProductClick(params.buildPostBody()).subscribeOn(Schedulers.io()).observeOn
                (AndroidSchedulers.mainThread()).subscribe(new Consumer<BaseEntity>() {
            @Override
            public void accept(BaseEntity bean) throws Exception {
                if (getViewer() != null) {
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
            }
        }));

    }

}
